package com.demo.datastructure.reorder.selectorSort;


import com.demo.datastructure.reorder.insertionSort.MyInsertionSort;

/**
 * @description: 选择排序
 * @author: ljr
 * @time: 2021/5/2 17:15
 */
public class MySelectorSort {

    public static void selectorSort(int[] args, int n){
        for(int i = 0; i < n-1; i++){
            int min = args[i];
            int k = i+1;
            boolean flag = true;
            for(; k < n; k++){
                if(min > args[k]){
                    int val = args[k];
                    args[k] = min;
                    min = val;
                    flag = false;
                }
            }

            if(flag){
                break;
            }else{
                args[i] = min;
            }
        }
    }

    public static void main(String[] args) {
        int[] nums = new int[]{3,3,2,5,1,6};
        MyInsertionSort.insertionSort(nums,6);
        for(int num : nums){
            System.out.println(num);
        }
    }
}
